import request from '@/utils/request'

/**
 * 创建或修改任务
 * http://heartisan.online:3000/project/15/interface/api/54
 * @param {object} data
 * @param {string} data.goal 任务目标
 * @param {string} data.dueDate 到期日
 * @param {string} data.id 如果为空则为创建，否则为修改
 */
export const create = (data) => (request({
  url: '/mission/create',
  method: 'post',
  data
}))

/**
 * 删除任务
 * http://heartisan.online:3000/project/15/interface/api/63
 * @param {string} id
 */
export const del = (id) => (request({
  url: `/mission/delete/${id}`,
  method: 'post'
}))

/**
 * 创建或修改任务
 * http://heartisan.online:3000/project/15/interface/api/72
 * @param {object} data
 * @param {number} data.missionId 任务 ID
 * @param {string} data.content 关键结果内容
 * @param {string} data.dueDate 到期日
 */
export const addKeyResult = (data) => (request({
  url: '/mission/addKeyResult',
  method: 'post',
  data
}))

/**
 * 任务详情
 * http://heartisan.online:3000/project/15/interface/api/81
 * @param {object} data
 * @param {string} data.missionId
 */
export const detail = ({ missionId }) => (request({
  url: `/mission/${missionId}`,
  method: 'get'
}))

/**
 * 我的任务列表
 * http://heartisan.online:3000/project/15/interface/api/90
 * @param {object} data
 * @param {number} data.pageNumber
 * @param {number} data.pageSize
 * @param {boolean} data.isInGroup
 */
export const fetchMyMissions = ({ pageNumber, pageSize, ...data }) => {
  console.log(data)
  return request({
    url: `/mission/fetchMyMissions/${pageNumber}/${pageSize}`,
    data,
    method: 'post'
  })
}

/**
 * 所有任务列表
 * @param {object} data
 * @param {number} data.pageNumber
 * @param {number} data.pageSize
 * @param {boolean} data.isInGroup
 * http://heartisan.online:3000/project/15/interface/api/99
 */
export const fetchAllMissions = ({ pageNumber, pageSize, ...data }) => {
  console.log(data)
  return request({
    url: `/mission/fetchAllMissions/${pageNumber}/${pageSize}`,
    method: 'post',
    data
  })
}

/**
 * 移除关键结果
 * http://heartisan.online:3000/project/15/interface/api/117
 * @param {number} keyResultId
 */
export const deleteKeyResult = (keyResultId) => (request({
  url: `/mission/deleteKeyResult${keyResultId}`,
  method: 'post'
}))

/**
 * http://heartisan.online:3000/project/15/interface/api/171
 * 目标评分
 * @param {object} data
 * @param {string} data.missionId
 * @param {string} data.score
 */
export const missionScore = (data) => (request({
  url: '/mission/missionScore',
  method: 'post',
  data
}))

/**
 * 目标关注
 * http://heartisan.online:3000/project/15/interface/api/180
 * @param {object} data
 * @param {string} data.missionId
 */
export const missionFocus = (data) => (request({
  url: '/mission/missionFocus',
  method: 'post',
  data
}))

/**
 * 目标取消关注
 * http://heartisan.online:3000/project/15/interface/api/189
 * @param {object} data
 * @param {string} data.missionId
 */
export const missionCancleFocus = (data) => (request({
  url: '/mission/missionCancleFocus',
  method: 'post',
  data
}))

/**
 * 更新目标查看次数
 * http://heartisan.online:3000/project/15/interface/api/306
 * @param {object} data
 * @param {string} data.missionId
 */
export const missionVisit = ({ missionId }) => (request({
  url: `/mission/missionVisit/${missionId}`,
  method: 'post'
}))
